package com.cuz.daileetcode;

import com.cuz.daileetcode.utils.TreeNode;
import javafx.util.Pair;

public class Day32_1 {


    public static boolean isFullTree(TreeNode root) {
        Pair<Integer, Integer> rootRes = process(root);
        int height = rootRes.getKey();
        int nodeNums = rootRes.getValue();
        return nodeNums == Math.pow(2, height)-1;
    }

    //key 高度 v 节点个数
    public static Pair<Integer, Integer> process(TreeNode node) {
        if (node == null) {
            return new Pair<>(0, 0);
        }
        Pair<Integer, Integer> rInfo = process(node.right);
        Pair<Integer, Integer> lInfo = process(node.left);
        int thisNodeHeight = Math.max(rInfo.getKey(), lInfo.getKey()) + 1;
        int thisNodeNum = rInfo.getValue() + lInfo.getValue() + 1;
        return new Pair<>(thisNodeHeight, thisNodeNum);
    }
}
